<template>
    
    <!-- 组件的模板 -->
    <div class="weui-cells" >
        <a class="weui-cell weui-cell_access" href="javascript:;" @click="selectWorkTime">
            <div class="weui-cell__bd">
                <p>每天最短工作时间</p>
            </div>
            <div class="weui-cell__ft">{{workTimeLength}} <template v-if="workTimeLength">小时</template></div>
        </a>
    </div>
</template>

<script>
    /**
     *  引入工具类库 或 Native API
     *  example : import widget from 'gapi/widget'
     */
    
    /**
     *  引入组件 以及 组件接口(Action)
     *  example : import Somecomponents from 'components/Somecomponents/Somecomponents'
     */
    import widget from 'gapi/widget'
    import cache from 'gapi/cache.js'
    import commonPage from 'clientApi/commonPage.js'
    import clientUi from 'gapi/clientUi.js'


    /**
     *  组件实例对象
     */
    export default {
        components: {
 
        },
        data: function(){
            return{
                workTimeLength:''
            }
        },
        vuex: {
            getters: {

            },
            actions: {

            }
        },
        methods: {
            /**
             * 初始化
             * @method init
             * @public
             * @return {Null} void
             */
            init (){
                cache.getMemoryCache('KqworkTimeLength', (data) => {
                    console.log(data)
                    if(data){
                        this.workTimeLength = data.key
                    }
                })
            },
            selectWorkTime(){
                let data = {
                    data1: []
                }
                let select = ['0']
                for(let i = 1 ; i<24.5 ; i+=0.5){
                    data.data1.push(i)
                }
                if(this.workTimeLength){
                    select[0]=data.data1.indexOf(Number(this.workTimeLength))+''
                }
                clientUi.showPicker(data, select, '工作时间(小时)', (returnData) => {
                    this.workTimeLength = data.data1[returnData.data1]
                })
            },
            submit(){
                console.log(this.workTimeLength)
                if(this.workTimeLength){
                    commonPage.goBack(1,{'key':'workTimeLength','value':this.workTimeLength})
                }else{
                    widget.toast('请选择弹性工作时段')
                }
                
            }
        },
        created(){

            this.init()
             /**
             * 设置 添加考勤任务按钮
             * @type {String}
             */
            commonPage.updateTitleBar({
                backAction: '',
                leftDisplay: false,
                leftText: '',
                leftAction: '',
                rightDisplay: true,
                rightText: '提交',
                rightAction: 'doSubmit'
            })

            window.doSubmit = this.submit
        }
        
    }

    
</script>

<!-- CSS 样式 -->
<style src="../../node_modules/weui/dist/style/weui.css"></style>
